{extend name="common:base" /}
{block name="page_current"}
<div class="fui-page-group statusbar">
    <style>
        .checkbox-inline input[type=checkbox], .radio-inline input[type=radio] {
            position: absolute;
            margin-left: -1.2rem;
            top: -.15rem;
        }
        .fui-list-inner .title{
            display: -webkit-box;  display: -webkit-flex;  display: -ms-flexbox;  display: flex;
        }
        .fui-list-inner .title .realname{
            max-width: 2rem;
            display: inline-block;
            max-width: 12rem;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            padding-right: 1.2rem;
        }
        .fui-list-inner .address{
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
    </style>
    <div class="fui-page address-selector-page fui-page-current" id="page-address">
        <div class="fui-header">
            <div class="fui-header-left">
                <a class="back"></a>
            </div>
            <div class="title" style="padding-left: 1.5rem">收货地址</div>
        </div>
        <div class="fui-content">
            <div id="noaddress" class="content-empty" style="display:none">
                <!--<i class='icon icon-location'></i>-->
                <!--<br/>您还没有任何收货地址-->
                <img src="__STATIC__/m/imgs/noadd.png" style="width: 6rem;margin-bottom: .5rem;"><br><p style="color: #999;font-size: .75rem">您暂时没有任何收货地址哦！</p>
            </div>
            <div id="addresslist">
            </div>
        </div>
        <div class="fui-navbar">
            <a href="{:url('Member/address_post')}" class="nav-item btn btn-danger external" data-nocache="true"><i class="icon icon-add"></i> 新增地址</a>
        </div>
        <script id="tpl_address_item" type="text/html">
            {{#  layui.each(d.list, function(index, item){ }}
            <div class="fui-list-group address-item" style="margin-top:5px;" data-addressid="{{ item.id }}">
                <div class="fui-list">
                    <div class="fui-list-inner">
                        <div class="title"><span class="realname">{{ item.realname }}</span> <span class="mobile">{{ item.mobile }}</span></div>
                        <div class="text">
                            <span class="address">{{ item.address }}</span>
                        </div>
                        <div class="bar">
                            <span class="pull-right">
                                <a class="external" href="{{ item.edit_url }}" data-nocache="true">
                                <i class="icon icon-edit2"></i> 编辑
                                </a>
                                &nbsp;&nbsp;
                                <a href="javascript:delAddress({{ item.id }});" class="external">
                                <i class="icon icon-delete"></i> 删除
                                </a>
                            </span>
                            <label class="radio-inline" onclick="setDefaultAddress({{ item.id }})">
                                {{#  if(item.is_default){ }}
                                <input type="radio" name="setdefault" data-toggle="setdefault" class="fui-radio  fui-radio-danger" checked=""> 设置默认
                                {{# }else{ }}
                                <input type="radio" name="setdefault" data-toggle="setdefault" class="fui-radio  fui-radio-danger"> 设置默认
                                {{#  } }}
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            {{#  }); }}
        </script>
    </div>
    <script src="__STATIC__/layer/layui.js"></script>
    <script src="__STATIC__/layer/laytpl.js"></script>
    <script src="https://cdn.bootcss.com/store.js/1.3.20/store.min.js"></script>
    <script>
        function getAddressList() {
            core.json("{:url('m/Member/get_address_list')}",{keyword:$('#search').val()},function (json) {
                if(json.code){
                    var view = document.getElementById('addresslist');
                    if(json.data.length > 0){
                        $('#noaddress').hide(0);
                        var getTpl = $('#tpl_address_item').text();
                        layui.laytpl(getTpl).render({list:json.data}, function(html){
                            view.innerHTML = html;
                        });
                    }
                    else{
                        view.innerHTML = '';
                        $('#noaddress').show(0);
                    }
                }
            },true,false);
        }
        getAddressList();
        $(function () {
            $('#search').on('blur',function () {
                getAddressList();
            })
        })
        function setDefaultAddress(_id) {
            console.log(_id);
            core.json("{:url('Member/address_set_default')}", {id: _id}, function (ret) {
                if (ret.code == 1) {
                    getAddressList();
                }
            }, true, true)
        }
        function delAddress(_id) {
            FoxUI.confirm('确认删除该地址吗？', function () {
                core.json("{:url('Member/address_delete')}", {id: _id}, function (ret) {
                    if (ret.code == 1) {
                        getAddressList();
                    }
                    FoxUI.toast.show(ret.msg)
                }, true, true)
            })
        }
    </script>
</div>
{/block}

{block name="script"}{/block}